% TEST_ID: LANG-CONTROL-FLOW-0011
% CATEGORY: language/control-flow
% switch 语句

function test_switch
    A = "a";
    switch A
        case 1
            B = 1;
        case 'a'
            B = 'a';
        otherwise
            B = "otherwise";
    end

    assert(B == 'a')

    A = 1;
    switch A
        case 'a'
            B = 'a';
        case 1
            B = 1;
        otherwise
            B = "otherwise";
    end

    assert(B == 1)


    plottype = 'pie3';
    switch plottype
        case 'bar'
            B = 'bar';
        case {'tie', 'pie3'}
            B = 'tie or pie3';
        otherwise
            B = 'otherwise';
    end

    assert(B == 'tie or pie3')

    assert(test_switch_(1) == 1)
    assert(test_switch_(2) == 1)
    assert(test_switch_(3) == 2)
    assert(isequal(test_switch_('1234'), '123'))
    assert(test_switch_('abcd') == "abcd")
    assert(test_switch_("abcd") == "abcd")
    assert(isequal(test_switch_("1234"), '123'))
    assert(isequal(test_switch_("456"), '456'))
    assert(test_switch_('ggg') == "ggg")

end


function y = test_switch_(x)
    switch x
        case {1, 2}
            y = 1;
        case {'789', '456'}
            y = '456';
        case "abcd"
            y = "abcd";
        case ["ggg", "ggg"]
            y = "ggg";
        case '1234'
            y = '123';
        otherwise
            y = 2;
    end
end